home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / haeberli / libgutil / mysystem.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  2KB  |  64 lines

  1. /*
  2.  * Copyright 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*
  18.  *      mysystem -
  19.  *              A rehacked and better system.
  20.  *
  21.  *                              Paul Haeberli - 1993
  22.  */
  23. #include <stdio.h>
  24. #include <signal.h>
  25. #include <errno.h>
  26. #include <sys/wait.h>
  27.  
  28. static char bin_shell[] = "/bin/sh";
  29. static char shell[] = "sh";
  30. static char shflg[]= "-c";
  31.  
  32. extern int _fork(), _execl();
  33.  
  34. int system(const char *s)
  35. {
  36.     int    status, pid, w;
  37.     struct sigaction oldistat;
  38.     int NewStyle;
  39.  
  40.     NewStyle = 1;
  41.     if (s == NULL) return(1);
  42.     if (_sigaction(SIGINT,NULL,&oldistat) == -1) {
  43.     if (_oserror() == EINVAL)
  44.         NewStyle = 0;
  45.     else
  46.         return(-1);
  47.     }
  48.     if ((pid = _fork()) == 0) {
  49.     (void) _execl(bin_shell, shell, shflg, s, (char *)0);
  50.     _exit(127);
  51.     }
  52.     if (pid < 0) {
  53.     w = -1;
  54.     } else {
  55.     if (NewStyle) {
  56.         w = _waitpid(pid,&status,0);
  57.     } else {
  58.         while ((w = _wait(&status)) != pid && w != -1)
  59.         ;
  60.     }
  61.     }
  62.     return((w == -1)? w: status);
  63. }
  64.